package pww.dao.adminImpl;

import a.annotation.Component;
import pww.dao.AdministratorDao;
import pww.entity.Administrator;
import pww.entity.Student;
import pww.utils.ConnUtil;
import dbUtil.ResultsetHandler;
import dbUtil.SQLExecute;
import dbUtil.handler.BeanHandler;
import pww.utils.SQlExcuteFactory;

import java.sql.Connection;
/**
 * 管理员登录的实现类
 */
@Component
public class LoginAdminDaoImpl implements AdministratorDao {
    //管理员登录
    public Administrator isLogin(String account,String password) {
        Connection connection = ConnUtil.getConnection();
        String sql="select * from administrator where account=? and password=?";
        ResultsetHandler<Administrator> handler=new BeanHandler<Administrator>(Administrator.class);
        SQLExecute sqlExecute=new SQLExecute(connection);
        Administrator administrator1 = sqlExecute.executeQuery(sql, handler,account,password);
        System.out.println("hh"+administrator1);
        return administrator1;
    }
    //修改信息前显示单个学生信息
    public Student select(Integer id){
        String sql="select * from student where id=?";
        SQLExecute sqlExecute = SQlExcuteFactory.openSqlExcute();
        ResultsetHandler<Student> handler=new BeanHandler<>(Student.class);
        Student student = sqlExecute.executeQuery(sql, handler, id);
        return student;
    }
    //修改学生信息
    public void updateStudent(Student student){
        String sql="update student set name=?,age=?,addr=?,sex=?,loving=? where id=?";
        SQLExecute sqlExecute = SQlExcuteFactory.openSqlExcute();
        sqlExecute.executeUpdate(sql,student.getName(),student.getAge(),student.getAddr(),student.getSex(),student.getClasses(),student.getLoveing(),student.getId());
    }
    //删除学生信息
    public void deleteStudent(Integer id){
        String sql="delete from student where id=?";
        SQLExecute sqlExecute = SQlExcuteFactory.openSqlExcute();
        sqlExecute.executeUpdate(sql,id);
    }
}
